import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    // meta: { isRouterAuth: true },
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'el-icon-s-home' }
    }]
  },
  {
    path: '/notify',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Notify',
        component: () => import('@/views/notify/index'),
        meta: { title: '通知管理', icon: 'el-icon-message-solid' }
      },
    ]
  },
  {
    path: '/course',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Course',
        component: () => import('@/views/course/index'),
        meta: { title: '课程管理', icon: 'el-icon-s-management' }
      },
    ]
  },
  {
    path: '/semester',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'semester',
        component: () => import('@/views/semester/index'),
        meta: { title: '学期管理', icon: 'el-icon-s-marketing' }
      },
    ]
  },

  {
    path: '/orders',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Orders',
        component: () => import('@/views/orders/index'),
        meta: {
          title: '订单列表', icon: 'el-icon-s-order'
        },
      }
    ]
  },
  {
    path: '/address',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Address',
        component: () => import('@/views/address/index'),
        meta: {
          title: '地址管理', icon: 'el-icon-location'
        },
      }
    ]
  },

  {
    path: '/student',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Student',
        component: () => import('@/views/student/index'),
        meta: { title: '学生管理', icon: 'el-icon-user-solid' }
      }
    ]
  },
  {
    path: '/admin',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Admin',
        component: () => import('@/views/admin/index'),
        meta: { title: '管理员', icon: 'el-icon-s-custom' }
      }
    ]
  },
  { path: '*', redirect: '/404', hidden: true }
]



const createRouter = () => new Router({
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})



const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
